package router

import (
	"go-project/common/middleware"
	"go-project/internal/api"

	"github.com/gin-gonic/gin"
)

var Engine *gin.Engine

func Init() {
	g := gin.New()
	g.Use(gin.Logger())
	//g.Use(logger.GinLogger()) //注册gin日志

	authMiddleware, err := middleware.GinJWTMiddleware()
	if err != nil {
		panic(err)
	}
	g.POST("/login", authMiddleware.LoginHandler)
	//需要登录后访问的接口
	auth := g.Group("")
	auth.Use(authMiddleware.MiddlewareFunc(), middleware.CasbinMiddleware())
	//PrivateGroup.Use(middleware.JwtAuthMiddleware(), middleware.CasbinMiddleware())
	{
		api.TestApi.Route(auth)

		api.UserApi.Route(auth)
	}
	//无需登录访问的接口
	//open := g.Group("")
	//{
	//	api.UserApi.PublicRoute(open)
	//}
	Engine = g
}
